%% Create new schedule for Behavior RIG 1

% File Name | warning: file will be overwritten without prompting
sch = 'Rat_NB_Test.mat';
FN = ['C:\Behavior\Human Spectral-Notch Detection\Schedule Files\' sch];

clear schedule trialdef

%% parameter tags

% for RPvds direct access
schedule.writeparams = {'trial_type1','stim_delay1'};

% use neg values for PA5 index; use 0 (zero) for file
schedule.writemodule = [1 1 1];
schedule.readparams  = {'trial_type1','response_code1'};
schedule.readmodule  = [1 1];
schedule.nreps       = 1;
schedule.randomize   = true;
schedule.schedule    = sch;
% schedule.ITI         = 2.5;

%% Check yo' self
if length(schedule.writeparams) ~= length(schedule.writemodule)
	error('write params/module lengths differ!');
end

if length(schedule.readparams) ~= length(schedule.readmodule)
	error('read params/module lengths differ!');
end

%% trial defs
clear trialdef

stimfilepath = 'C:\Behavior\Human Spectral-Notch Detection\Stim Files\';

% Trial-type codes ('BB' = Broad Band; 'SN' = Spectral Notch)
% 0 = BB vs BB
% 1 = BB vs SN
% 2 = SN vs SN
% 3 = SN vs BB
trialdef{1} = {'buddy','trial_type',[0 0 ones(1,4)*2 ones(1,4)*3 ones(1,4)*1]};
% Buffer~1
trialdef{2} = {'buddy','trial_type', { ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat'], ...                
                [stimfilepath 'Fc2000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc4000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc6000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc8000Hz_BW0.3oct.mat'], ...              
                [stimfilepath 'Fc2000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc4000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc6000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc8000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat']}};                
% Buffer~2
trialdef{3} = {'buddy','trial_type', { ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat'], ...                
                [stimfilepath 'Fc2000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc4000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc6000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc8000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat'], ...                
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'BB.mat'], ...
                [stimfilepath 'Fc2000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc4000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc6000Hz_BW0.3oct.mat'], ...
                [stimfilepath 'Fc8000Hz_BW0.3oct.mat']}};                

% controls PA5 attenuators
trialdef{4} = {'buddy','stimlevl',[15]};
trialdef{5} = {'buddy','stimlevl',[15]};

trialdef{6} = {1500}; % stimulus onset asynchrony

%% Get Unique Trials
schedule = BHVR_AddTrial(schedule,trialdef);


%% Save

save(FN,'schedule');

